﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using BEGDC.CC.BL.Common;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.Common
{
    /// <summary>
    /// Summary description for AssignApp.
    /// </summary>
    public class AssignAppForESC : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lblStaff;
        protected System.Web.UI.WebControls.Button btnAssign;
        protected System.Web.UI.WebControls.DropDownList ddlCODStaff;
        protected System.Web.UI.HtmlControls.HtmlTableCell txtHint;
        protected System.Web.UI.WebControls.Button ibtnClose;
        protected System.Web.UI.WebControls.RadioButtonList rbESCEVPApprove;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_chooseStaff;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                this.btnAssign.Attributes["onclick"] = "javascript:OnAssign();";
                BindCODStaff();

                if (Request.QueryString["IsESC"].ToUpper() == "TRUE")
                    this.rbESCEVPApprove.Enabled = true;
                else if (Request.QueryString["IsESC"].ToUpper() == "FALSE")
                    this.rbESCEVPApprove.Enabled = false;

                if (Request.QueryString["IsCheck"] == "Y")
                    this.tr_chooseStaff.Visible = false;
            }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnAssign.Click += new EventHandler(btnAssign_Click);
            this.ibtnClose.Click += new EventHandler(ibtnClose_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion

        private void BindCODStaff()
        {
            BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
            DataTable table = null;
            if (Request.QueryString["IsFilter"] == null || Request.QueryString["IsFilter"] == "true")
            {
                table = utility.GetOCOStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), true);
            }
            else
            {
                table = utility.GetOCOStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), false);
            }

            if (table == null || table.Rows.Count == 0)
            {
                this.txtHint.InnerHtml = "There aren't any OCOStaffs. If you want to assign the request, please contact role admin to add one";
            }
            else
            {
                this.ddlCODStaff.DataSource = table;
                this.ddlCODStaff.DataValueField = "EmployeeNo";
                this.ddlCODStaff.DataTextField = "NameEN";
                this.ddlCODStaff.DataBind();
            }
        }

        void btnAssign_Click(object sender, EventArgs e)
        {
            Response.Write(@"<Script>returnValue='" + this.ddlCODStaff.SelectedValue + "_" + this.rbESCEVPApprove.SelectedItem.Text + "';self.close(); </Script>");
        }

        void ibtnClose_Click(object sender, EventArgs e)
        {
            Response.Write(@"<Script>returnValue='%close%';self.close(); </Script>");
        }
    }
}
